package com.project.app.server.broadroom;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.server.domain.broadroom.TBroadroomBook;
import com.project.server.service.broadroom.ITBroadroomBookService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 小程序预约会议室
 */
@RestController
@RequestMapping("/app/server/book")
public class ATBroadroomBookController extends BaseController {

    @Resource
    private ITBroadroomBookService tBroadroomBookService;

    /**
     * 查询会议室预约列表
     */
    //@PreAuthorize("@ss.hasPermi('server:book:list')")
    @GetMapping("/list")
    public TableDataInfo list(TBroadroomBook tBroadroomBook) {
        startPage();
        List<TBroadroomBook> list = tBroadroomBookService.selectTBroadroomBookList(tBroadroomBook);
        return getDataTable(list);
    }
    
    /**
     * 通过预约时间段查询会议室预约列表
     */
    //@PreAuthorize("@ss.hasPermi('server:book:list')")
    @GetMapping("/")
    public AjaxResult getBookList(TBroadroomBook tBroadroomBook) {
        return AjaxResult.success(tBroadroomBookService.selectTBroadroomBookBybookStart(tBroadroomBook));
    }

    /**
     * 根据预约人电话号码获取会议室预约详细信息
     */
    //@PreAuthorize("@ss.hasPermi('server:book:query')")
    @GetMapping(value = "/{phone}")
    public AjaxResult getInfo(TBroadroomBook tBroadroomBook) {
        return AjaxResult.success(tBroadroomBookService.selectTBroadroomBookByPhone(tBroadroomBook));
    }

    /**
     * 新增会议室预约
     */
    @Log(title = "会议室预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TBroadroomBook tBroadroomBook) {
        return toAjax(tBroadroomBookService.insertTBroadroomBook(tBroadroomBook));

    }

    /**
     * 修改预约状态
     */
    @Log(title = "会议室预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TBroadroomBook tBroadroomBook) {
        return toAjax(tBroadroomBookService.updateBookStatus(tBroadroomBook));
    }

}
